<?php
class ControllerShippingAusPost extends AdminController {
	
	public function index() {   
		
		$this->document->setTitle($this->_['heading_title']);
		
		M('setting/setting');
		
		if ($this->request->isPost() && $this->validate()) {
			$this->model_setting_setting->editSetting('auspost', $this->request->post);             
			
			$this->session->set_flashdata('success', $this->_['text_success']);			
			$this->redirect(UA('extension/shipping'));
		}
		
		$this->data['breadcrumbs'] = array();
		
		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_home'],
			'href'      => UA('common/home'),
      		'separator' => false
		);
		
		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['text_shipping'],
			'href'      => UA('extension/shipping'),
      		'separator' => ' :: '
		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->_['heading_title'],
			'href'      => UA('shipping/auspost'),
      		'separator' => ' :: '
   		);
		
		
		M('localisation/weight_class');		
		$this->data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
		
		M('localisation/tax_class');		
		$this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
		
		M('localisation/geo_zone');		
		$this->data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
		
		$this->display('shipping/auspost.tpl');
	}
	
	protected function validate() {
		if (!$this->hasMP()) {
			$this->setMessage('error_warning', $this->_['error_permission']);
			return false;
		}
		
		if (!preg_match('/^[0-9]{4}$/', $this->request->post['auspost_postcode'])){
			$this->setMessage('error_postcode', $this->_['error_postcode']);
			return false;
		}
	
		return true;
	}
}
?>